import axios from './axios'
import qs from 'qs'
import {baseUrl} from '@/config/config'
// 获取学生列表
export const getStudentList = (params) => {
  return new Promise((resolve, reject) => {
    axios({
      url: baseUrl + '/bdc/api/app/student',
      method: 'get',
      params
    }).then(res => {
      resolve(res)
    })
  })
}
// 获取单个学生信息
export const getSingleStudent = (params) => {
  return new Promise((resolve, reject) => {
    axios({
      url: baseUrl + '/bdc/api/app/student/' + params,
      method: 'get'
    }).then(res => {
      resolve(res.data)
    })
  })
}
// 获取所有年级
export const getAllGradeApi = (params) => {
  return new Promise((resolve, reject) => {
    axios({
      url: baseUrl + '/bdc/api/app/school/grades',
      method: 'get',
      params
    }).then(res => {
      resolve(res.data.items)
    })
  })
}
// 获取该学校的所有班级
export const addStudentApi = (params) => {
  return new Promise((resolve, reject) => {
    axios({
      url: baseUrl + '/bdc/api/app/school/' + params.id + '/classes',
      method: 'get',
      params: params.data
    }).then(res => {
      resolve(res.data.items)
    })
  })
}
// 获取所有的学届（ 学籍 ）
export const addLearnApi = (params) => {
  return new Promise((resolve, reject) => {
    if (!params.id) {
      resolve([])
      return
    }
    axios({
        url: baseUrl + '/bdc/api/app/school/' + params.id + '/peroids',
        method: 'get',
        params: params.data
    }).then(res => {
      resolve(res.data.items)
    })
  })
}
// 批量导入学生数据 （未使用）
export const importStudent = (data) => {
    return new Promise((resolve, reject) => {
      axios({
          url: baseUrl + '/bdc/api/app/school/' + data.schoolId + '/students',
          method: 'post',
          data: data.body
      }).then(res => {
          resolve(res.data)
      }).catch(err => {
        reject(err)
      })
  })
}
// 删除学生
export const deleteStudentsApi = (params) => {
    return new Promise((resolve, reject) => {
      axios({
          url: baseUrl + '/bdc/api/app/student/' + params,
          method: 'delete'
      }).then(res => {
          resolve(res)
      })
  })
}
// 学籍变动接口
export const studentChangeApi = (params) => {
    return new Promise((resolve, reject) => {
      axios({
          url: baseUrl + '/bdc/api/app/users/' + params.id + '/record',
          method: 'post',
          data: params.body
      }).then(res => {
          resolve(res)
      })
  })
}

// 更新学生信息
export const toUpdateApi = (params) => {
    return new Promise((resolve, reject) => {
      axios({
          url: baseUrl + '/bdc/api/app/student/' + params.id,
          method: 'put',
          data: params.data
      }).then(res => {
          resolve(res)
      })
  })
}

// 新增学生
export const newStudentsApi = (params) => {
    return new Promise((resolve, reject) => {
      axios({
          url: baseUrl + '/bdc/api/app/student/',
          method: 'post',
          data: params.data
      }).then(res => {
          resolve(res)
      })
  })
}

// 获取全部学段
export const allSectionsApi = (params) => {
    return new Promise((resolve, reject) => {
      axios({
          url: baseUrl + '/bdc/api/app/school/' + params + '/stages',
          method: 'get'
      }).then(res => {
          resolve(res.data.items)
      })
  })
}

// 枚举请求
export const enumerationApi = (params) => {
    return new Promise((resolve, reject) => {
      axios({
          url: baseUrl + '/bdc/api/app/dictionaryvalue',
          method: 'get',
          params
      }).then(res => {
          resolve(res.data)
      })
  })
}

// 获取学生变动记录
export const changeRecordApi = (params) => {
    return new Promise((resolve, reject) => {
      axios({
          url: baseUrl + '/bdc/api/app/users/' + params.id + ' /records',
          method: 'get',
          params: params.data
      }).then(res => {
          resolve(res.data)
      })
  })
}

// 监测登录名是否被占用
export const monitorApi = (params) => {
    return new Promise((resolve, reject) => {
      axios({
          url: baseUrl + '/bdc/api/app/users/user',
          method: 'get',
          params
      }).then(res => {
         resolve(res.data.items)
      }).catch(err => {
        reject(err)
      })
  })
}

// 添加，修改，删除亲属关系
export const handleRelativesApi = (params) => {
  return new Promise((resolve, reject) => {
    axios({
        url: baseUrl + '/bdc/api/app/student/' + params.id + '/parentMappings',
        method: 'post',
        data: params.data
    }).then(res => {
       resolve(res)
    }).catch(err => {
      reject(err)
    })
  })
}

// 解除用户微信登录状态
export const unbindApi = (params) => {
  return new Promise((resolve, reject) => {
    axios({
        url: baseUrl + '/bdc/api/app/users/' + params + '/wechatLogin',
        method: 'delete'
    }).then(res => {
       resolve(res)
    }).catch(err => {
      reject(err)
    })
  })
}

// 根据学段和学级获取到  当下对应年级
export const correspondingGradeApi = (params) => {
  return new Promise((resolve, reject) => {
    axios({
        url: baseUrl + '/bdc/api/app/school/' + params.id + '/grade',
        method: 'get',
        params: params.data
    }).then(res => {
       resolve(res)
    }).catch(err => {
      reject(err)
    })
  })
}
